from math import sqrt


class MyMath:
    """
    用类封装一个Math类, 实现加, 减, 乘, 除, 幂, 开方
    """
    def __init__(self):
        print('__init__called')

    # 加法addition
    def add(self, *args):
        res = 0
        for i in range(len(args)):
            res += args[i]
        return res

    # 减法subtraction
    def sub(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            res -= args[i]
        return res

    # 乘法multiplication
    def mul(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            res *= args[i]
        return res

    # 除法division
    def div(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            assert args[i] != 0
            res /= args[i]
        return res

    # 整除
    def div_z(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            assert args[i] != 0
            res //= args[i]
        return res

    # 取余remainder
    def rem(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            res %= args[i]
        return res

    # 乘方Power
    def pow(self, *args):
        res = args[0]
        for i in range(1, len(args)):
            res **= args[i]
        return res

    # 开方Square root
    def sqr(self, x):
        return sqrt(x)


# 自定义基类
class ProgramingLanguage:
    """
    自由课题, 按照自己的想法, 将身边的事物抽象成类, 并创建多个实例.
    """
    total = 50
    def __init__(self):
        print('__init__ called')

    def get_rank(self):
        rank_list = {"C": 1, "Python": 2, "Java": 3, "C++": 4, "C#": 5}
        return rank_list


class Python(ProgramingLanguage):
    data_type = ["Int（整数）", "Float（浮点数）", "String（字符串）",
                 "Boolean（布尔值）", "None（空）", "Bytes（字节）"]
    data_structure = ["set", "list", "dict", "tuple"]

    def __init__(self, rank):
        super(Python, self).__init__()
        self.__founder = 'Guido'
        self.rank = rank

    def can_do(self):
        return 'Python能做web应用开发、网络爬虫、AI人工智能与数据科学、数据分析！'


class Java(ProgramingLanguage):
    def __init__(self, rank):
        super(Java, self).__init__()
        self.__founder = 'James Gosling'
        self.rank = rank

    def can_do(self):
        return 'Java能开发网站，Android应用，PC端，游戏等'


if __name__ == '__main__':
    my_math = MyMath()
    res_add = my_math.add(1, 2, 2)
    print(res_add)
    res_sub = my_math.sub(1, 2, 2)
    print(res_sub)
    res_mul = my_math.mul(1, 2, 2)
    print(res_mul)
    res_div = my_math.div(1, 2, 2)
    print(res_div)
    res_div_z = my_math.div_z(1, 2, 2)
    print(res_div_z)
    res_rem = my_math.rem(1, 2, 1)
    print(res_rem)
    res_pow = my_math.pow(2, 3, 2)
    print(res_pow)
    res_sqr = my_math.sqr(3)
    print(res_sqr)

    python = Python(2)
    print(f'访问实例的属性：{python.rank}')
    print(f'访问实例的方法：{python.can_do()}')
    print(f'访问父类的属性：{python.total}')
    print(f'访问父类的方法：{python.get_rank()}')

    java = Java(3)
    print(f'访问实例的属性：{java.rank}')
    print(f'访问实例的方法：{java.can_do()}')
    print(f'访问父类的属性：{java.total}')
    print(f'访问父类的方法：{java.get_rank()}')